import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let userInfo = JSON.parse(localStorage.getItem('uersInfo'))
if(!userInfo) {
  userInfo = {}
}

const store = new Vuex.Store({
  state: {
    age: 18,
    userInfo: userInfo
  },
  getters: {

  },
  mutations: {
    // 保存用户数据
    setUserInfo(state, data) {
      state.userInfo = data;
      // 再localStorage中也存一份
      // 本地持久化存储
      localStorage.setItem('uersInfo',JSON.stringify(data))
    }
    // 清除用户数据
  },
  actions: {

  }
})
export default store